//
//  ShopCollectionCell.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/13.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "ShopCollectionCell.h"

@interface ShopCollectionCell()

/**
 店铺Icon
 */
@property (nonatomic, strong) UIImageView *shopIcon;


/**
 店铺名称
 */
@property (nonatomic, strong) UILabel *shopNameLab;


/**
 店铺内容
 */
@property (nonatomic, strong) UILabel *shopContentLab;


/**
 店铺销量
 */
@property (nonatomic, strong) UILabel *shopSalesLab;


/**
 评分
 */
@property (nonatomic, strong) UILabel *scoreLab;


/**
 灰色星
 */
@property (nonatomic, strong) UIView *grayView;


/**
 
 黄色星
 */
@property (nonatomic, strong) UIView *yellowView;


/**
 分数
 */
@property (nonatomic, assign) CGFloat scoreNum;


/**
 寄宿View
 */
@property (nonatomic, strong) UIView *view;


@end


@implementation ShopCollectionCell

#pragma mark - lifecycle methods

- (void)setupUI
{
    // 添加子控件
    [self addSubview:self.shopIcon];
    [self addSubview:self.shopNameLab];
    [self addSubview:self.shopContentLab];
    [self addSubview:self.shopSalesLab];
    [self addSubview:self.scoreLab];
    [self addSubview:self.grayView];
    [self addSubview:self.yellowView];
}

- (void)setupLayout
{
    [self addShadowAndCircleCorner:_shopIcon.layer corner:8];
    
    {
        _shopIcon.size = CGSizeMake(64, 64);
        _shopIcon.mj_x = _shopIcon.mj_y = 15;
    }
    
    {
        _shopNameLab.mj_x = 15 + _shopIcon.right;
        _shopNameLab.mj_y = 15;
        _shopNameLab.width = KScreenWidth - _shopNameLab.left - 15;
    }
    
    _shopNameLab.height = 21;
    
    {
        _shopContentLab.mj_x = _shopNameLab.left;
        _shopContentLab.mj_y = 4 +_shopNameLab.bottom;
        _shopContentLab.width = _shopNameLab.width;
        _shopContentLab.height = 18;
    }
    
    
    {
        _grayView.mj_x = _shopNameLab.left;
        _grayView.mj_y = _shopContentLab.bottom + 7;
        
        _yellowView.mj_x = _grayView.mj_x;
        _yellowView.mj_y = _grayView.mj_y;
    }
    
    {
        _scoreLab.mj_x = _grayView.right + 5;
        _scoreLab.mj_y = _grayView.top;
        _scoreLab.width = 30;
        _scoreLab.height = 17;
    }
    
    {
        _shopSalesLab.mj_x = _scoreLab.right + 5;
        _shopSalesLab.mj_y = _shopContentLab.bottom + 9;
        _shopSalesLab.width = KScreenWidth - _shopSalesLab.left - 15;
        _shopSalesLab.height = 17;
    }

    
    {
        _shopNameLab.text = @"行走的铺子";
        _shopContentLab.text = @"我是新店家，别的不敢说，猪肉绝对新鲜和…";
        _scoreLab.text = @"4.9";
        _shopSalesLab.text = @"累计销量4396";
        _shopIcon.backgroundColor = KYellowColor;
    }

}



#pragma mark - setter methods

- (void)setScoreNum:(CGFloat)scoreNum{
    
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    
    NSInteger aims = scoreNum/0.5;
    NSInteger index = aims/2;
    
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, IconW *scoreNum + IconG*index, IconW)];
    maskLayer.path = path.CGPath;
    self.yellowView.layer.mask = maskLayer;
}


//- (void)setModel:(BuyMeatModel *)model{
//
//    self.shopNameLab.text = model.shopName;
//    self.shopContentLab.text = model.autograph;
//    NSString *saleNume = [NSString stringWithFormat:@"%@", model.saleNum];
//    self.shopSalesLab.text = [@"累计销量" stringByAppendingString:saleNume];
//    [self.shopIcon sd_setImageWithURL:[NSURL URLWithString:model.imgName]];
//}

#pragma mark -  getter methods

- (UIImageView *)shopIcon{
    
    if (!_shopIcon) {
        _shopIcon = [[UIImageView alloc] init];
    }
    return _shopIcon;
}


//店铺名称
- (UILabel *)shopNameLab{
    
    if (!_shopNameLab) {
        _shopNameLab = [[UILabel alloc] init];
        _shopNameLab.textColor = UIColorFromRGB(0x262626);
        _shopNameLab.font = mMediumFont(16);
    }
    return _shopNameLab;
}


//店铺内容
- (UILabel *)shopContentLab{
    
    if (!_shopContentLab) {
        _shopContentLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x63656A) font:mFont(12) textAliment:0];
        _shopContentLab.numberOfLines = 0;
    }
    return _shopContentLab;
}


//店铺销量
- (UILabel *)shopSalesLab{
    
    if (!_shopSalesLab) {
        _shopSalesLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x999999) font:mFont(12) textAliment:0];
    }
    return _shopSalesLab;
}

- (UILabel *)scoreLab{
    
    if (!_scoreLab) {
        _scoreLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0xFDC60A) font:mFont(12) textAliment:0];
    }
    return _scoreLab;
}

- (UIView *)grayView{
    
    if (!_grayView) {
        _grayView = [[UIView alloc] init];
        _grayView.size = CGSizeMake(IconW *5 + IconG *4, IconW);
        
        for (NSInteger i = 0; i< 5; i++) {
            UIImageView *icon = [[UIImageView alloc] init];
            icon.frame = CGRectMake((IconW+IconG)*i , 0, IconW, IconW);
            icon.image = [UIImage imageNamed:@"like_starRank_gray"];
            [_grayView addSubview:icon];
        }
    }
    return _grayView;
}


- (UIView *)yellowView{
    
    if (!_yellowView) {
        _yellowView = [[UIView alloc] init];
        _yellowView.size = CGSizeMake(IconW *5 + IconG *4, IconW);
        
        for (NSInteger i = 0; i< 5; i++) {
            UIImageView *icon = [[UIImageView alloc] init];
            icon.frame = CGRectMake((IconG+IconW)*i, 0, IconW, IconW);
            icon.image = [UIImage imageNamed:@"like_starRank_yellow"];
            [_yellowView addSubview:icon];
        }
    }
    return _yellowView;
}

@end
